// TOWN SCRIPT
//    Town 0: Registration Temple

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

//FLAGS
//(0,0) = state 0: arrival
//(0,1) = state 10: spider statue
//(0,2) = state 11: storage
//(0,3) = state 13: fridge
//(0,4) = state 14: guest
//(0,5) = state 15: foyer
//(0,6) = state 16: sanctuary
//(0,7) = state 17: office
//(0,8) = state 18: portal room
//(0,9) = guest dead
//(3,0) = talknode 11: give completed form
//(3,1) = talknode 17: Eph grew trees
//(3,2) = talknode 20: you don't need to come here
//(3,3) = talknode 26: guest leaves
//(3,4) = talknode 12: complete Registration

begintownscript;

variables;
int i,j,k,lvl,choice;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered.
	if (get_flag(0,0) == 0) {
		reset_dialog_preset_options(0);
		add_dialog_str(0,"You arrive at the Registration Temple. To the east you see guest quarters, but your primary destination lies directly north.",0);
		choice = run_dialog(0);
		if (choice == 1)
			set_flag(0,0,1);
	}
	if ((get_flag(3,0) == 1) && (has_special_item(1) == 0))
		set_terrain(14,9,16);

	if ((get_flag(0,4) == 1) && (get_flag(3,3) == 0)){
		erase_char(14);
		relocate_character(13,33,13);
	}

	if (get_flag(3,3) == 1)
		erase_char(13);

//Names
	set_name(6,"Spider");
	set_name(7,"Tyranicus");
	set_char_dialogue_pic(7,506,0);
	set_name(8,"Nikki");
	set_char_dialogue_pic(8,513,0);
	set_name(9,"Luz");
	set_char_dialogue_pic(9,511,0);
	set_name(10,"Vogel");
	set_char_dialogue_pic(10,515,0);
	set_level(10,100);
	set_name(11,"Ephesos");
	set_char_dialogue_pic(11,514,0);
	set_name(12,"Nemesis");
	set_char_dialogue_pic(12,512,0);
	set_name(15,"Niemand");
	set_char_dialogue_pic(15,518,0);
	set_name(16,"Nioca");
	set_char_dialogue_pic(16,524,0);
	set_name(17,"Geneforged");
	set_char_dialogue_pic(17,526,0);
	set_name(18,"Arancaytar");
	set_char_dialogue_pic(18,528,0);
	set_name(19,"Andraste");
	set_char_dialogue_pic(19,522,0);
	set_name(20,"Dikiyoba");
	set_char_dialogue_pic(20,521,0);
	set_name(21,"Danilaniloudoff");
	set_level(21,50);
	set_aggression(21,100);
	set_courage(21,100);
	set_name(22,"Slartucker");
	set_level(22,50);
	set_aggression(22,100);
	set_courage(22,100);
	set_char_dialogue_pic(22,529,0);
	set_name(23,"Thralni");
	set_char_dialogue_pic(23,532,0);

	set_crime_tolerance(0);

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
	if (get_ran(1,0,100) < 6)


	if ((get_crime_level() > 0) || ((has_special_item(1) > 0) && (get_flag(1,5) == 0))){
		kill_char(1000,3,0);
		message_dialog("Spiderweb is very strict and timely in its criminal justice system.","You barely get anywhere before the supernatural forces guarding the temple strike you down.");
	}
break;

beginstate 10;
	if (get_flag(0,1) == 0){
		message_dialog("There's a statue of a spider in the middle of this pool. Strange decor for an otherwise pretty temple.","");
		set_flag(0,1,1);
	}
break;

beginstate 11;
	if (get_flag(0,2) == 0){
		message_dialog("This appears to be a storage warehouse. This is where all the temple's supplies are kept.","It looks like someone was trying to organize it at one point, but then gave up.");
		set_flag(0,2,1);
	}
break;

beginstate 12;
	if ((get_flag(1,5) == 1) && (has_special_item(1) == 0)){
		message_dialog("Don't forget to pick up your Blades of Avernum License from Vogel before you go.","");
		block_entry(1);
	}
break;

beginstate 13;
	if (get_flag(0,3) == 0){
		message_dialog("It's noticeably colder in this room, apparently because it's where the food is stored.","How this is done, you cannot tell. It must be by some magical means.");
		set_flag(0,3,1);
	}
break;

beginstate 14;
	if (get_flag(0,4) == 0){
		text_bubble_on_char(14,"psst hey! over heer!");
		force_instant_terrain_redraw();
		pause(10);
		text_bubble_on_char(14,"");
		force_instant_terrain_redraw();
		pause(5);
		erase_char(14);
		message_dialog("You hear the whisper first, then begin looking for its source.","");
		relocate_character(13,33,13);
		text_bubble_on_char(13,"yeah you! come heer!");
		force_instant_terrain_redraw();
		pause(10);
		text_bubble_on_char(13,"");
		message_dialog("When you look closely into the bushes next to the temple, you can see a robed humanoid standing there.","Even upon closer look, you cannot see his (or her) face, or any other defining feature, for that matter.");
		set_flag(0,4,1);
	}
break;

beginstate 15;
	if (get_flag(0,5) == 0){
		message_dialog("This is the foyer of the Registration Temple. It's this building where you can begin the Ritual of Registration.","Now you just have to find this _Vogel_ person and get further instructions from him.");
		set_flag(0,5,1);
	}
break;

beginstate 16;
	if (get_flag(0,6) == 0){
		message_dialog("This room looks like it's the sanctuary of this temple. Why exactly a temple like this needs a sanctuary, you're really not sure. There can't be much to say in a sermon.","Sure enough, the room is so clean it looks like it's never used. Only one person is even here now.");
		set_flag(0,6,1);
	}
break;

beginstate 17;
	if (get_flag(0,7) == 0){
		reset_dialog_preset_options(0);
		add_dialog_str(0,"The sign at the door says that this is Vogel's office. That must mean the man at the desk is Vogel. He is busily working on something. He glances up when you enter, beckons you forward, and begins speaking.",0);
		add_dialog_str(1,"_Hello, adventurer. Let me guess why you're here, just so we're on the same page. You were adventuring. And then, out of nowhere, there's the Shareware Demon, saying you can't go any further, right?_",0);		add_dialog_str(2,"You nod. He's quite correct. _Alright,_ he says. _Then it's time for you to perform the Ritual of Registration. Here._ He hands you a slip of paper. _Fill this out, then return it to me when you're done._",0);
		choice = run_dialog(0);
		if (choice == 1){
			char_give_item(0,447);
			set_flag(0,7,1);
		}
	}
break;

beginstate 18;
	if (get_flag(0,8) == 0){
		message_dialog("This small room only contains a portal. Presumably, it will take you to the place where you can complete the Ritual of Registration.","");
		set_flag(0,8,1);
	}
break;

beginstate 19;
	if (get_flag(1,5) == 0){
		reset_dialog();
		add_dialog_str(0,"This portal will take you to fight the demon. Are you ready to do this?",0);
		add_dialog_choice(0,"Not yet.");
		add_dialog_choice(1,"Yes, I'm ready.");
		choice = run_dialog(0);
		if (choice == 1){
			block_entry(1);
			end();
		}
		if (choice == 2)
			move_to_new_town(1,2,4);
	}
	else{
		message_dialog("You've already beaten the Shareware Demon; it won't bother you anymore. What more do you want?","");
		block_entry(1);
	}
break;

beginstate 20;
	large_draw_pic_dialog(531,"This appears to be a chart of some kind of tournament. It's hard to tell exactly what it is, though.");
break;